import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';


/// @author jltxseo
///         Created by junlintianxia on 2020/04/21.
class RouterTestRoute extends StatelessWidget {
  const RouterTestRoute({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
        child: Column(
      children: <Widget>[
        ElevatedButton(
          onPressed: () {
            //跳转到新的页面路由
            // Navigator.push(context, MaterialPageRoute(builder: (context) {
            //   return NewRoute();
            // }));
            // 跳转到新的页面路由
            context.push('/newRoute');
          },
          child: Text("open new route"),
        ),
        ElevatedButton(
          onPressed: () async {
            // var result = await Navigator.of(context)
            //     .push(MaterialPageRoute(builder: (context) {
            //   return TipRoute(
            //     text: "我是提示xxx",
            //   );
            // }));
            var result = await context.push('/tip?text=我是提示xxx');
            print("路由返回值: $result");
          },
          child: Text("打开提示页"),
        ),
        ElevatedButton(
          onPressed: () async {
            // var result = await Navigator.of(context)
            //     .pushNamed("tip", arguments: "我是提示xxxTip");
            var result = await context.push('/tip?text=我是提示tip');
            print("路由返回值: $result");
          },
          child: Text("打开提示页Tip"),
        ),
        ElevatedButton(
          onPressed: () async {
            // var result = await Navigator.of(context)
            //     .pushNamed("tip2", arguments: "我是提示xxxTip2");
            var result = await context.push('/tip2?text=我是提示tip2');

            print("路由返回值: $result");
          },
          child: Text("打开提示页Tip2"),
        ),
        ElevatedButton(
          onPressed: () async {
            // var result = await Navigator.of(context)
            //     .pushNamed("tip3", arguments: "路由钩子");
            var result = await context.push('/tip3');
            LogUtil.v("路由返回值: $result");
          },
          child: Text("打开路由钩子"),
        ),
      ],
    ));
  }
}

class NewRoute extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("New route"),
      ),
      body: Center(
        child: Text("This is new route"),
      ),
    );
  }
}

class TipRoute extends StatelessWidget {
  final String text;

  const TipRoute({
    super.key,
    required this.text,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("提示"),
      ),
      body: Padding(
        padding: EdgeInsets.all(18),
        child: Center(
          child: Column(
            children: <Widget>[
              Text(text),
              ElevatedButton(
                onPressed: () => Navigator.pop(context, "我是返回值"),
                child: Text("返回"),
              )
            ],
          ),
        ),
      ),
    );
  }
}
